package com.danbay.framework.utils;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;

public class ArrayUtils extends org.apache.commons.lang3.ArrayUtils{

    /**
     * 根据对象的key进行数据的去重
     *R
     * @param keyExtractor
     * @param <T>
     * @return
     */
    public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
        Map<Object, Boolean> map = new ConcurrentHashMap<>();
        return t -> map.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
    }

    public static boolean isNullOrEmpty(Collection collection){
        if (null == collection || collection.isEmpty()) {
            return true;
        }
        return false;
    }
}
